package com.wogu.strutstest.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.hibernate.Session;

import com.wogu.strutstest.model.Account;

public class AccountDao {
    
    private HibernateTemplate hibernateTemplate;
    
    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
    
    public Account getUserByName(String userName) {
        final String hsql = "FROM Account WHERE nick=?";
        Account account = null;
        try {
            List<Account> result = hibernateTemplate.find(hsql, userName);
            account = result.get(0);
        } catch(Exception e) {
            
        }
        
        return account;
    }
    
    public List<Account> getUsers() {
        return hibernateTemplate.find("FROM Account");
    }
}